//
//  ZhuceViewController.m
//  用户登录软件界面
//
//  Created by ibokan on 14-10-29.
//  Copyright (c) 2014年 ibokan. All rights reserved.
//

#import "ZhuceViewController.h"

@interface ZhuceViewController ()
@property (strong, nonatomic) IBOutlet UITextField *zhucezhanghao;
@property (strong, nonatomic) IBOutlet UITextField *zhucemima;
@property (strong, nonatomic) IBOutlet UITextField *zhucemima1;


- (IBAction)zhuce:(UIButton *)sender;
- (IBAction)viewclicked:(id)sender;

- (IBAction)goback:(UIButton *)sender;

@end

@implementation ZhuceViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)zhuce:(UIButton *)sender {
    
    
    if (self.zhucezhanghao.text.length == 0) {
        
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"新用户注册" message:@"骚年，请输入账号！" delegate:self cancelButtonTitle:@"知道了！" otherButtonTitles:nil];
        [alert show];
    }else{
    NSUserDefaults *userdefaults = [NSUserDefaults standardUserDefaults];
    if ([userdefaults objectForKey:[NSString stringWithFormat:@"%@",self.zhucezhanghao.text]] == nil) {
        if ([self.zhucemima.text isEqual:self.zhucemima1.text]) {
            [userdefaults setObject:self.zhucemima1.text forKey:self.zhucezhanghao.text];
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"新用户注册" message:@"骚年，恭喜你注册成功，成为快乐小2b用户的一员！" delegate:self cancelButtonTitle:@"太好了！" otherButtonTitles:nil];
            [alert show];
            
            self.zhucezhanghao.text = nil;
            self.zhucemima.text = nil;
            self.zhucemima1.text = nil;
        }else{
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"新用户注册" message:@"对不起，您两次的密码填写不一致！" delegate:self cancelButtonTitle:@"知道了！" otherButtonTitles:nil];
            [alert show];
            self.zhucemima.text = nil;
            self.zhucemima1.text = nil;
        }

    }else{
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"新用户注册" message:@"对不起，您注册的账号已存在！" delegate:self cancelButtonTitle:@"知道了！" otherButtonTitles:nil];
        [alert show];
        self.zhucezhanghao.text = nil;
        self.zhucemima.text = nil;
        self.zhucemima1.text = nil;
    }
        [userdefaults synchronize];
    }

    
}

- (IBAction)viewclicked:(id)sender {
    [self.zhucezhanghao resignFirstResponder];
    [self.zhucemima resignFirstResponder];
    [self.zhucemima1 resignFirstResponder];
}

- (IBAction)textfileddone:(UITextField *)sender {
    [sender resignFirstResponder];
}



- (IBAction)goback:(UIButton *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}
@end
